class UserModel {
  int? code;
  Data? data;
  String? msg;

  UserModel({this.code, this.data, this.msg});

  UserModel.fromJson(Map<String, dynamic> json) {
    code = json['code'];
    data = json['data'] != null ? new Data.fromJson(json['data']) : null;
    msg = json['msg'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['code'] = this.code;
    if (this.data != null) {
      data['data'] = this.data!.toJson();
    }
    data['msg'] = this.msg;
    return data;
  }
}

class Data {
  User? user;
  String? token;
  int? expiresAt;

  Data({this.user, this.token, this.expiresAt});

  Data.fromJson(Map<String, dynamic> json) {
    user = json['user'] != null ? new User.fromJson(json['user']) : null;
    token = json['token'];
    expiresAt = json['expiresAt'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.user != null) {
      data['user'] = this.user!.toJson();
    }
    data['token'] = this.token;
    data['expiresAt'] = this.expiresAt;
    return data;
  }
}

class User {
  int? id;
  String? uuid;
  String? userName;
  String? nickName;
  String? headerImg;
  String? phone;
  String? email;
  int? enable;
  int? authorityId;
  Authority? authority;
  List<dynamic>? departments;
  List<dynamic>? authorities;

  User(
      {this.id,
      this.uuid,
      this.userName,
      this.nickName,
      this.headerImg,
      this.phone,
      this.email,
      this.enable,
      this.authorityId,
      this.authority,
      this.departments,
      this.authorities});

  User.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    uuid = json['uuid'];
    userName = json['userName'];
    nickName = json['nickName'];
    headerImg = json['headerImg'];
    phone = json['phone'];
    email = json['email'];
    enable = json['enable'];
    authorityId = json['authorityId'];
    authority = json['authority'] != null
        ? new Authority.fromJson(json['authority'])
        : null;
    if (json['departments'] != null) {
      departments = <dynamic>[];
      json['departments'].forEach((v) {
        departments!.add(v);
      });
    }
    if (json['authorities'] != null) {
      authorities = <Null>[];
      json['authorities'].forEach((v) {
        authorities!.add(v);
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['uuid'] = this.uuid;
    data['userName'] = this.userName;
    data['nickName'] = this.nickName;
    data['headerImg'] = this.headerImg;
    data['phone'] = this.phone;
    data['email'] = this.email;
    data['enable'] = this.enable;
    data['authorityId'] = this.authorityId;
    if (this.authority != null) {
      data['authority'] = this.authority!.toJson();
    }
    if (this.departments != null && this.departments!.isNotEmpty) {
      data['departments'] = departments!.map((v) => v.toJson()).toList();
    } else {
      data['departments'] = []; // 如果 departments 为 null 或空，设置为空数组
    }

    if (this.authorities != null && this.authorities!.isNotEmpty) {
      data['authorities'] = this.authorities!.map((v) => v.toJson()).toList();
    } else {
      data['authorities'] = []; // 如果 authorities 为 null 或空，设置为空数组
    }
    return data;
  }
}

class Authority {
  int? authorityId;
  String? authorityName;
  String? roleCode;
  String? defaultRouter;

  Authority(
      {this.authorityId,
      this.authorityName,
      this.roleCode,
      this.defaultRouter});

  Authority.fromJson(Map<String, dynamic> json) {
    authorityId = json['authorityId'];
    authorityName = json['authorityName'];
    roleCode = json['roleCode'];
    defaultRouter = json['defaultRouter'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['authorityId'] = this.authorityId;
    data['authorityName'] = this.authorityName;
    data['roleCode'] = this.roleCode;
    data['defaultRouter'] = this.defaultRouter;
    return data;
  }
}

class MyUserData {
  static UserModel? userModel;
}
